<?php
namespace app\payqr\model;
use app\BaseModel;

class CardTimelineThumbs extends BaseModel{
//定义表名
    protected $name = 'longbing_card_timeline_thumbs';
    //用户是否点赞
    public function is_fabulous($user_id,$timeline_id,$uniacid){
        $data = [
          'user_id'=>$user_id,
          'timeline_id'=>$timeline_id,
          'status'=>1,
          'uniacid'=>$uniacid,
        ];
         return $this->where($data)->value('id');
    }
    public function createTimelineThumb($data){
        return $this->save($data);
    }
    //删除点赞
    function delTimelineThumb($id){
        $data['id'] = $id;
        $result = $this->destroyRow($data);
        if(empty($result)) return false;
        return true;
    }
    //查询点赞的用户
    public function getUserFabulous($timeline_id,$limit){
        return $this->alias( 'a' )
            ->where('timeline_id',$timeline_id)
            ->field('b.id,b.avatarUrl')
            ->join( 'longbing_card_user b', 'a.user_id = b.id')
            ->limit($limit)
            ->order('a.create_time','desc')
            ->select();
    }
    //查询动态被点赞的次数
    public function fabulousCount($where){
       return $this->where($where)->count();
    }
}